﻿using System.Collections.Generic;
using System.Threading;
using System.Data;

namespace WBrowser
{
    public class HttpThread
    {
        private Thread _thread = null;
        public Links _parentForm = null;
        private List<string> urlList = new List<string>();
        private BrowserSession _browser;

        public HttpThread()
        {

        }

        #region start threads functions

        /// <summary>
        /// Start threads get thread url of forum
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="url"></param>
        public void startThread_GetIdThreads(Links parent, DataRow drTemplate)//, DataTable dbThreadTemplate)
        {
            _parentForm = parent;
            _browser = new BrowserSession();
            _browser.pTemplateRow = drTemplate;
            //_browser.pThreadTemplateTable = dbThreadTemplate;

            _thread = new Thread(new ThreadStart(GetIdThreads));
            _thread.Start();
        }

        /// <summary>
        /// Start threads get thread url of forum
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="url"></param>
        public void startThread_GetThreadIdByRegex(Links parent, string url, DataRow drTemplate)
        {
            _parentForm = parent;
            _browser = new BrowserSession();
            _browser.pTemplateRow = drTemplate;
             
            _thread = new Thread(new ThreadStart(GetThreadIdByRegex));
            _thread.Name = url;
            _thread.Start();
        }

        /// <summary>
        /// Start threads get thread url of forum
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="url"></param>
        public void startThread_CheckForumInformation(Links parent, DataRow drTemplate)
        {
            _parentForm = parent;
            _browser = new BrowserSession();
            _browser.pTemplateRow = drTemplate;
           
            _thread = new Thread(new ThreadStart(CheckForumInformation));
            _thread.Start();
        }

        /// <summary>
        /// Start threads check login
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="url"></param>
        public void startThread_CheckLogin(Links parent, DataRow drTemplate)
        {
            _parentForm = parent;
            _browser = new BrowserSession();
            _browser.pTemplateRow = drTemplate;
            
            _thread = new Thread(new ThreadStart(CheckLogin));
            _thread.Start();
        }

        /// <summary>
        /// Start threads check login
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="url"></param>
        public void startThread_FindStatisticsUrl(Links parent, DataRow drTemplate)
        {
            _parentForm = parent;
            _browser = new BrowserSession();
            _browser.pTemplateRow = drTemplate;
            
            _thread = new Thread(new ThreadStart(FindStatisticsUrl));
            _thread.Start();
        }


        /// <summary>
        /// Check post
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="url"></param>
        public void startThread_FindPost(Links parent, DataRow drTemplate, DataRow drPost, DataRow drForumPost)
        {
            _parentForm = parent;
            _browser = new BrowserSession();
            _browser.pTemplateRow = drTemplate;
            _browser.pPostsRow = drPost;
            _browser.pForumPostsRow = drForumPost;
            _thread = new Thread(new ThreadStart(FindPost));
            _thread.Start();
        }
        #endregion

        #region delegate function
        delegate void updateProgressDelegate();
        private void updateProgress()
        {
            if (this._parentForm.dataGridViewForums.InvokeRequired)
            {
                // this is worker thread
                updateProgressDelegate del = new updateProgressDelegate(updateProgress);
                this._parentForm.dataGridViewForums.Invoke(del);
            }
            else
            {
                //this._parentForm.UpdateProgess(_browser.pTemplateRow);
                //this._parentForm.checkForumsBindingSource.EndEdit();
                //this._parentForm.dataGridViewCheckForums.DataSource = this._parentForm.checkForumsBindingSource;
                //this._parentForm.dataGridViewCheckForums.Refresh();
                //this._parentForm.dataGridViewCheckForums.Update();

                //=========================================================================================================================================
                // this is UI thread
                this._parentForm._urlList.Add(_browser.pTemplateRow["url"].ToString());
                this._parentForm._selectedForums--;

                this._parentForm.toolStripProgressBar1.Step = (100 / (this._parentForm.toolStripProgressBar1.Maximum - this._parentForm._selectedForums));
                this._parentForm.toolStripProgressBar1.PerformStep();

                if (this._parentForm._selectedForums == 0)
                {
                    this._parentForm.toolStripStatusLabelComplete.Text = "Complete!";
                    this._parentForm._selectedForums--;
                }
                //=========================================================================================================================================
            }
        }

        delegate void updateProgressGridViewDelegate(params object[] values);
        private void updateProgressGridView(params object[] values)
        {
            if (this._parentForm.dataGridViewForumThreads.InvokeRequired)
            {
                // this is worker thread
                updateProgressGridViewDelegate del = new updateProgressGridViewDelegate(updateProgressGridView);
                this._parentForm.dataGridViewForumThreads.Invoke(del, new object[] { values });
            }
            else
            {
                int index = this._parentForm.threadTemplatesBindingSource.Find("url", values[0]);
                this._parentForm.dataGridViewForumThreads.Rows[index].Cells["threadidDataGridViewTextBoxColumnThread"].Value = values[1];

                //=========================================================================================================================================
                // this is UI thread
                this._parentForm._urlList.Add(_browser.pTemplateRow["url"].ToString());
                this._parentForm._selectedForums--;

                //Update progress bar
                this._parentForm.toolStripProgressBar1.Step = (100 / (this._parentForm.toolStripProgressBar1.Maximum - this._parentForm._selectedForums));
                this._parentForm.toolStripProgressBar1.PerformStep();

                if (this._parentForm._selectedForums == 0)
                {
                    this._parentForm.toolStripStatusLabelComplete.Text = "Complete!";
                    this._parentForm._selectedForums--;
                }
                //=========================================================================================================================================
            }
        }


        delegate void updateProgressIdThreadsDelegate();
        private void updateProgressIdThreads()
        {
            if (this._parentForm.dataGridViewForumThreads.InvokeRequired)
            {
                // this is worker thread
                updateProgressIdThreadsDelegate del = new updateProgressIdThreadsDelegate(updateProgressIdThreads);
                this._parentForm.dataGridViewForumThreads.Invoke(del);
            }
            else
            {
                this._parentForm.threadTemplatesBindingSource.EndEdit();
                if (this._parentForm.comboBoxSelectForum.SelectedIndex == 0)
                {
                    this._parentForm.threadTemplatesBindingSource.RemoveFilter();
                }
                else
                {
                    this._parentForm.threadTemplatesBindingSource.Filter = "forum_name = '" + this._parentForm.comboBoxSelectForum.SelectedValue + "'";
                }
                this._parentForm.dataGridViewCheckForums.Update();//.Refresh();

                //Update progress bar
                this._parentForm._selectedForums--;
                this._parentForm.toolStripProgressBar1.Step = (100 / (this._parentForm.toolStripProgressBar1.Maximum - this._parentForm._selectedForums));
                this._parentForm.toolStripProgressBar1.PerformStep();

                if (this._parentForm._selectedForums == 0)
                {
                    this._parentForm.toolStripStatusLabelComplete.Text = "Complete!";
                    this._parentForm._selectedForums--;
                }
            }
        }
        #endregion

        public void GetIdThreads()
        {
            _browser.GetIdThreads(this._parentForm.mpconfigDataSet.ThreadTemplates);
            updateProgressIdThreads();
        }

        public void GetThreadIdByRegex()
        {
            string thread_id = _browser.GetThreadIdByRegex(_thread.Name);
            updateProgressGridView(_thread.Name, thread_id);
        }


        /// <summary>
        /// Check content forums:
        /// Type:       App, Porn, Both, Dead
        /// Language:   English, VietNamese, Germany, Italian
        /// Forum:      vBulletin, phpBB2, phpBB2, myBB, Ip.Board
        /// </summary>
        public void CheckForumInformation()
        {
            _browser.GetForumInformation();
            updateProgress();
        }

        /// <summary>
        /// Check Login
        /// </summary>
        public void CheckLogin()
        {
            _browser.DoLogin();
            updateProgress();
        }

        /// <summary>
        /// Find statistics url:
        /// 1. login is successful 
        /// 2. Continue find a username url
        /// 3. Finally, find a statistics url
        /// </summary>
        public void FindPost()
        {
            _browser.FindPost();
            updateProgress();
        }

        /// <summary>
        /// Find statistics url:
        /// 1. login is successful 
        /// 2. Continue find a username url
        /// 3. Finally, find a statistics url
        /// </summary>
        public void FindStatisticsUrl()
        {
            _browser.FindStatisticsUrl();
            updateProgress();
        }

        //#region Old Code

        ///// <summary>
        ///// Get user id in new thread url
        ///// </summary>
        ///// <param name="url"></param>
        //public string GetUserId(string url)
        //{
        //    string userid = "";
        //    Regex r = new Regex(@"(f=(?<id>\d{2,})|/(?<id>\d{2,})");
        //    Match m = r.Match(url);
        //    if (m.Success)
        //        userid = m.Value;
        //    return userid;
        //}

        ///// <summary>
        ///// Update a row in datagridview
        ///// </summary>
        ///// <param name="threadId"></param>
        //delegate void updateRowGridViewDelegate(string threadId);
        //private void updateRowGridView(string threadId)
        //{
        //    if (this._parentForm.dataGridViewForumThreads.InvokeRequired)
        //    {
        //        // this is worker thread
        //        updateRowGridViewDelegate update = new updateRowGridViewDelegate(updateRowGridView);
        //        this._parentForm.dataGridViewForumThreads.Invoke(update, new object[] { threadId });
        //    }
        //    else
        //    {
        //        // this is UI thread
        //        foreach (DataGridViewRow dr in this._parentForm.dataGridViewForumThreads.Rows)
        //        {
        //            if (dr.Cells["url"].Value.ToString() == _thread.Name)
        //            {
        //                this._parentForm.dataGridViewForumThreads.Rows[dr.Index].Cells["Id"].Value = threadId;
        //                break;
        //            }
        //        }
        //    }
        //}
        /////// <summary>
        /////// Add a new row in datagridview
        /////// </summary>
        /////// <param name="values"></param>
        ////delegate void addARowGridViewDelegate();
        ////private void addARowGridView()
        ////{
        ////    if (this._parentForm.dataGridViewForumThreads.InvokeRequired)
        ////    {
        ////        // this is worker thread

        ////        addARowGridViewDelegate add = new addARowGridViewDelegate(addARowGridView);
        ////        this._parentForm.dataGridViewForumThreads.Invoke(add);
        ////    }
        ////    else
        ////    {
        ////        // this is UI thread
        ////        //this._parentForm.dataGridViewForumThreads.Rows.Add((string)values[0], (bool)values[1], (string)values[2], (string)values[3], (string)values[4], (string)values[5]);
        ////    }
        ////}

        ///// <summary>
        ///// Start threads get id threads of a forum
        ///// </summary>
        ///// <param name="parent"></param>
        ///// <param name="rowIndex">indexes of selected rows in datagridview</param>
        ///// <param name="url"></param>
        //public void startThread_GetThreadId(Links parent, string url)
        //{
        //    _parentForm = parent;
        //    _thread = new Thread(new ThreadStart(GetAsyncIdNewThread));
        //    _thread.Name = url;
        //    _thread.Start();
        //}

        ////delegate void updateProgressDelegate();
        ////private void updateProgress()
        ////{
        ////    if (this._parentForm.toolStripStatusLabelComplete.InvokeRequired)
        ////    {
        ////        // this is worker thread

        ////        updateProgressDelegate add = new updateProgressDelegate(updateProgress);
        ////        this._parentForm.toolStripStatusLabelComplete.Invoke(add, new object[] { values });
        ////    }
        ////    else
        ////    {
        ////        this._parentForm._urlList.Add(_browser.pTemplateRow["url"].ToString());
        ////        this._parentForm._selectedForums--;

        ////        this._parentForm.toolStripProgressBar1.Step = (100 / (this._parentForm.toolStripProgressBar1.Maximum - this._parentForm._selectedForums));
        ////        this._parentForm.toolStripProgressBar1.PerformStep();

        ////        if (this._parentForm._selectedForums == 0)
        ////        {
        ////            this._parentForm.toolStripStatusLabelComplete.Text = "Complete!";
        ////            this._parentForm._selectedForums--;
        ////        }
        ////    }
        ////}

        ////delegate void checkLogin_UpdateGridViewCheckForumsDelegate(params object[] values);
        ////private void checkLogin_UpdateGridViewCheckForums(params object[] values)
        ////{
        ////    if (this._parentForm.dataGridViewCheckForums.InvokeRequired)
        ////    {
        ////        // this is worker thread
        ////        checkLogin_UpdateGridViewCheckForumsDelegate del = new checkLogin_UpdateGridViewCheckForumsDelegate(checkLogin_UpdateGridViewCheckForums);
        ////        this._parentForm.dataGridViewCheckForums.Invoke(del, new object[] { values });
        ////    }
        ////    else
        ////    {
        ////        //Find key in datagridview
        ////        int index = this._parentForm.checkForumsBindingSource.Find("url", _browser.pTemplateRow["url"].ToString());
        ////        string forumname = this._parentForm.dataGridViewCheckForums.Rows[index].Cells["forumnameDataGridViewTextBoxColumn1"].Value.ToString();
        ////        //Find datarow with key in datatable
        ////        DataRow dr = this._parentForm.mpconfigDataSet.Tables["Templates"].Rows.Find(forumname);
        ////        //Update row
        ////        dr["loginstatus"] = values[0];
        ////        dr["html"] = values[1];

        ////        //add url have been view
        ////        this._parentForm._urlList.Add(_browser.pTemplateRow["url"].ToString());
        ////        this._parentForm._selectedForums--;

        ////        this._parentForm.toolStripProgressBar1.Step = (100 / (this._parentForm.toolStripProgressBar1.Maximum - this._parentForm._selectedForums));
        ////        this._parentForm.toolStripProgressBar1.PerformStep();
        ////        if (this._parentForm._selectedForums == 0)
        ////        {
        ////            this._parentForm.toolStripStatusLabelComplete.Text = "Complete!";
        ////            this._parentForm._selectedForums--;
        ////        }
        ////    }
        ////}

        ////delegate void findStatisticsUrl_UpdateGridViewCheckForumsDelegate(params object[] values);
        ////private void findStatisticsUrl_UpdateGridViewCheckForums(params object[] values)
        ////{
        ////    if (this._parentForm.dataGridViewCheckForums.InvokeRequired)
        ////    {
        ////        // this is worker thread
        ////        findStatisticsUrl_UpdateGridViewCheckForumsDelegate del = new findStatisticsUrl_UpdateGridViewCheckForumsDelegate(findStatisticsUrl_UpdateGridViewCheckForums);
        ////        this._parentForm.dataGridViewCheckForums.Invoke(del, new object[] { values });
        ////    }
        ////    else
        ////    {
        ////        int index = this._parentForm.checkForumsBindingSource.Find("url", _browser.pTemplateRow["url"].ToString());
        ////        string forumname = this._parentForm.dataGridViewCheckForums.Rows[index].Cells["forumnameDataGridViewTextBoxColumn1"].Value.ToString();
        ////        //Find datarow with key in datatable
        ////        DataRow dr = this._parentForm.mpconfigDataSet.Tables["Templates"].Rows.Find(forumname);
        ////        //Update row
        ////        dr["myposturl"] = values[0];
        ////        dr["userid"] = values[1];
        ////        dr["html"] = values[2];

        ////        this._parentForm._urlList.Add(_browser.pTemplateRow["url"].ToString());
        ////        this._parentForm._selectedForums--;

        ////        this._parentForm.toolStripProgressBar1.Step = (100 / (this._parentForm.toolStripProgressBar1.Maximum - this._parentForm._selectedForums));
        ////        this._parentForm.toolStripProgressBar1.PerformStep();

        ////        if (this._parentForm._selectedForums == 0)
        ////        {
        ////            this._parentForm.toolStripStatusLabelComplete.Text = "Complete!";
        ////            this._parentForm._selectedForums--;
        ////        }
        ////    }
        ////}

        ////delegate void findPost_UpdateGridViewPostedForumsDelegate(params object[] values);
        ////private void findPost_UpdateGridViewPostedForums(params object[] values)
        ////{
        ////    if (this._parentForm.dataGridViewPostedForums.InvokeRequired)
        ////    {
        ////        // this is worker thread
        ////        findPost_UpdateGridViewPostedForumsDelegate del = new findPost_UpdateGridViewPostedForumsDelegate(findPost_UpdateGridViewPostedForums);
        ////        this._parentForm.dataGridViewPostedForums.Invoke(del, new object[] { values });
        ////    }
        ////    else
        ////    {
        ////        //Find datarow with key in datatable
        ////        DataRow dr = this._parentForm.mpconfigDataSet.Tables["ForumPost"].Rows.Find(new object[]{_browser.pForumPostsRow["forum_name"].ToString(), _browser.pForumPostsRow["id"].ToString()});
        ////        //Update row
        ////        dr["update"] = values[0];

        ////        this._parentForm._urlList.Add(_browser.pTemplateRow["url"].ToString());
        ////        this._parentForm._selectedForums--;

        ////        //this._parentForm.toolStripProgressBar1.Step = (100 / (this._parentForm.toolStripProgressBar1.Maximum - this._parentForm._selectedForums));
        ////        //this._parentForm.toolStripProgressBar1.PerformStep();

        ////        if (this._parentForm._selectedForums == 0)
        ////        {
        ////            this._parentForm.toolStripStatusLabelComplete.Text = "Complete!";
        ////            this._parentForm._selectedForums--;
        ////        }
        ////    }
        ////}
        ///// <summary>
        ///// Get all urls with some filters
        ///// </summary>
        ////public void GetHrefs()
        ////{
        ////    try
        ////    {
        ////        HtmlWeb hw = new HtmlWeb();
        ////        HtmlAgilityPack.HtmlDocument doc = hw.Load(_thread.Name);
        ////        string title, url;
        ////        foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
        ////        {
        ////            url = link.Attributes["href"].Value;
        ////            foreach (HtmlNode node in link.ChildNodes)
        ////            {
        ////                title = node.InnerHtml;
        ////                //if (title.Contains("Appz"))
        ////                //    title = title;
        ////                if (node.Name == "strong" || node.Name == "#text" || node.Name == "span")
        ////                {
        ////                    if (this._parentForm.checkBoxKeyword.Checked)
        ////                    {
        ////                        //Kiểm tra url thỏa mãn điều kiện
        ////                        if (!this._parentForm.CheckUrlKeyWord((int)enumKeyType.BlacklistUrl, url)
        ////                        && !this._parentForm.CheckTitleKeyWord((int)enumKeyType.BlacklistTitle, title))
        ////                        {
        ////                            //Kiểm tra xem nội dung bên trong node có empty không
        ////                            if (url != string.Empty && title != string.Empty)
        ////                            {
        ////                                if (!urlList.Contains(url))
        ////                                {
        ////                                    //add key to List
        ////                                    urlList.Add(url);

        ////                                    //add result to datagridview
        ////                                 addARowGridView(_thread.Name, false, title, string.Empty, string.Empty, url);
        ////                                }
        ////                            }
        ////                        }
        ////                    }
        ////                    else
        ////                    {
        ////                        //Kiểm tra xem nội dung bên trong node có empty không
        ////                        if (url != string.Empty && title != string.Empty)
        ////                        {
        ////                            if (!urlList.Contains(url))
        ////                            {
        ////                                //add key to List
        ////                                urlList.Add(url);

        ////                                //add result to datagridview
        ////                                addARowGridView(_thread.Name, false, title, string.Empty, string.Empty, url);
        ////                            }
        ////                        }
        ////                    }
        ////                }
        ////                else if (node.Name == "img" || node.Name == "span" || node.Name == "font")
        ////                {
        ////                    //Code is here
        ////                }
        ////                else
        ////                {
        ////                    //Code is here
        ////                }
        ////            }
        ////        }
        ////    }
        ////    catch(Exception ex)
        ////    {
        ////        MessageBox.Show(ex.Message);
        ////    }
        ////}

        ///// <summary>
        ///// Stripping harmful HTML from user input
        ///// </summary>
        ///// <param name="doc"></param>
        ///// <returns></returns>
        //public string ScrubHTML(HtmlAgilityPack.HtmlDocument doc)
        //{
        //    //Remove potentially harmful elements
        //    HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//script|//link|//iframe|//frameset|//frame|//applet|//object|//embed");
        //    if (nc != null)
        //    {
        //        foreach (HtmlNode node in nc)
        //        {
        //            node.ParentNode.RemoveChild(node, false);
        //        }
        //    }

        //    //remove hrefs to java/j/vbscript URLs
        //    nc = doc.DocumentNode.SelectNodes("//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'javascript')]|//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'jscript')]|//a[starts-with(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'vbscript')]");
        //    if (nc != null)
        //    {

        //        foreach (HtmlNode node in nc)
        //        {
        //            node.SetAttributeValue("href", "#");
        //        }
        //    }


        //    //remove img with refs to java/j/vbscript URLs
        //    nc = doc.DocumentNode.SelectNodes("//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'javascript')]|//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'jscript')]|//img[starts-with(translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'vbscript')]");
        //    if (nc != null)
        //    {
        //        foreach (HtmlNode node in nc)
        //        {
        //            node.SetAttributeValue("src", "#");
        //        }
        //    }

        //    //remove on<Event> handlers from all tags
        //    nc = doc.DocumentNode.SelectNodes("//*[@onclick or @onmouseover or @onfocus or @onblur or @onmouseout or @ondoubleclick or @onload or @onunload]");
        //    if (nc != null)
        //    {
        //        foreach (HtmlNode node in nc)
        //        {
        //            node.Attributes.Remove("onFocus");
        //            node.Attributes.Remove("onBlur");
        //            node.Attributes.Remove("onClick");
        //            node.Attributes.Remove("onMouseOver");
        //            node.Attributes.Remove("onMouseOut");
        //            node.Attributes.Remove("onDoubleClick");
        //            node.Attributes.Remove("onLoad");
        //            node.Attributes.Remove("onUnload");
        //        }
        //    }

        //    // remove any style attributes that contain the word expression (IE evaluates this as script)
        //    nc = doc.DocumentNode.SelectNodes("//*[contains(translate(@style, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'expression')]");
        //    if (nc != null)
        //    {
        //        foreach (HtmlNode node in nc)
        //        {
        //            node.Attributes.Remove("stYle");
        //        }
        //    }

        //    return doc.DocumentNode.WriteTo();
        //}
        ///// <summary>
        ///// Get Id 
        ///// </summary>
        ///// <param name="url"></param>
        ///// <returns></returns>
        //public string GetIdByRegex(string url)
        //{
        //    string id = "";
        //    Regex rx = new Regex(@"newthread.php\?do=newthread&amp;(f=[0-9]+)");
        //    Match m = rx.Match(url);
        //    while (m.Success)
        //    {
        //        id = m.Value.Replace(@"newthread.php?do=newthread&amp;f=", "");
        //        m = m.NextMatch();
        //    }
        //    return id;
        //}

        ///// <summary>
        ///// Perform asynchoronize response
        ///// </summary>
        //public void GetAsyncIdNewThread()
        //{
        //    ClientGetAsync objAsyn = new ClientGetAsync(_thread.Name);
        //    string id = objAsyn.GetIdNewThread();
        //    updateRowGridView(id);
        //}

        ///// <summary>
        ///// Perform synchoronize response
        ///// </summary>
        //public void GetSyncIdNewThread()
        //{
        //    try
        //    {
        //        HtmlWeb hw = new HtmlWeb();
        //        HtmlAgilityPack.HtmlDocument doc = hw.Load(_thread.Name);
        //        HtmlAttribute att;
        //        string id = "";

        //        foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
        //        {
        //            att = link.Attributes["href"];
        //            id = GetIdByRegex(att.Value);
        //            if (id != string.Empty)
        //            {
        //                updateRowGridView(id);
        //                break;
        //            }
        //        }
        //    }
        //    catch (WebException we)
        //    {
        //        throw we;
        //    }
        //}
        //#endregion
    }
}
